#ifndef QEMU_AES_H
#define QEMU_AES_H

#include <string.h>
#include <stdint.h>

#define AES_MAXNR 14
#define AES_BLOCK_SIZE 16

struct aes_key_st {
    uint32_t rd_key[4 *(AES_MAXNR + 1)];
    int rounds;
};
typedef struct aes_key_st AES_KEY;

#ifdef __cplusplus
extern "C" 
{
#endif

/**
 * sets a new encryption key for AES
 * @param userKey the new user-specified key
 * @param bits number of bits used for encryption/decryption (either 128, 192 or 256)
 * @param key aes_key_st structure that contains current state of cryptographic algorithm
 */
int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key);

/**
 * sets a new decryption key for AES
 * @param userKey the new user-specified key
 * @param bits number of bits used for encryption/decryption (either 128, 192 or 256)
 * @param key aes_key_st structure that contains current state of cryptographic algorithm
 */
int AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key);

/**
 * encrypts single block
 * @param in buffer with block of data to be encrypted
 * @param out buffer that encrypted data will be written in
 * @param key aes_key_st structure that contains current state of cryptographic algorithm
 */
void AES_encrypt(const unsigned char *in, unsigned char *out,
	const AES_KEY *key);

/**
 * decrypt single block
 * @param in buffer with block of data to be decrypted
 * @param out buffer that decrypted data will be written in
 * @param key aes_key_st structure that contains current state of cryptographic algorithm
 */
void AES_decrypt(const unsigned char *in, unsigned char *out,
	const AES_KEY *key);

#ifdef __cplusplus
}  /* end extern "C" */
#endif

#endif
